const is = (val: unknown, type: string) => {
    return toString.call(val) === `[object ${type}]`;
};

const isObject = (val: any): val is Record<any, any> => {
    return val !== null && is(val, "Object");
};

export const isServer = typeof window === "undefined";
export const isClient = !isServer;

export const isWindow = (val: any): val is Window => {
    return typeof window !== "undefined" && is(val, "Window");
};

export const isElement = (val: unknown): val is Element => {
    return isObject(val) && !!val.tagName;
};

export const isDark = (): boolean => {
    return window.matchMedia("(prefers-color-scheme: dark)").matches;
};
